package com.firefly.mail.mailserver.helper;

import java.util.HashMap;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.firefly.mail.mailserver.bean.WordResultEntranceBean;
import com.firefly.mail.mailserver.bean.WordResultResponseObject;
import com.firefly.mail.mailserver.config.ErrorMap;
import com.firefly.mail.mailserver.service.AipOcrService;

/**
 * 
 * @author donnie
 * 图片文字解析的统一入口
 */
@Service("aipOcrEntrancePictureHelper")
public class AipOcrEntrancePictureHelper {
	
	static final String basicGeneral = "1";
	static final String enhancedGeneral = "2";
	static final String webImage = "3";
	
	private Log log = LogFactory.getLog(getClass());

	
	@Autowired
	private AipOcrService aipOcrService;
	
	
	@Autowired
	private ErrorMap errorMap;
	
	
	public WordResultResponseObject process(WordResultEntranceBean requestBean){
		try {
			if(requestBean != null){
				
				String entranceType=requestBean.getEntranceSecond();
				
				if(StringUtils.isNotEmpty(entranceType )){
					
					WordResultResponseObject response=null;
					
					switch (entranceType) {
					case basicGeneral:
						//通用的文字识别接口基础版
						response=aipOcrService.basicGeneral(requestBean);
						break;
					case enhancedGeneral:
						//通用的文字识别接口生僻字版本
						response=aipOcrService.enhancedGeneral(requestBean);
						break;
					case webImage:
						//网络图片文字识别接口
						response=aipOcrService.webImage(requestBean);
						break;
					default:
						break;
					}
					return errorMap.parseErrerParam(response);
					
				}
			}
		} catch (Exception e) {
			log.error("",e);
		}
		return null;
	}
	
	
	
}
